//
//  Card.m
//  CardSwitchDemo
//
//  Created by Apple on 2016/11/9.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "XLMsgCard.h"
#import "XLCardItem.h"
#import "SINAUiviewClickLiserner.h"
#import "SINACalendarUtils.h"

@interface XLMsgCard () {
    
    //日期
    UILabel *_dayLabel;
    //时间
    UILabel *_timeLabel;
    UILabel *_timeDiviLabel;
    //消息
    UILabel *_msgContentLabel;
    UIView  *_mainView;
}
@end

@implementation XLMsgCard

- (instancetype)initWithFrame:(CGRect)frame {
    
    return [self initWithFrame:frame :YES];
}
- (instancetype)initWithFrame:(CGRect)frame :(BOOL)isShowTitle{
    if (self = [super initWithFrame:frame]) {
        [self buildUI:isShowTitle];
    }
    return self;
}
- (void)buildUI :(BOOL)isShowTitle{
    self.layer.cornerRadius =7.0f;
    self.layer.masksToBounds = true;
    self.backgroundColor = [UIColor whiteColor];
    
//    CGFloat labelHeight = self.bounds.size.height;
    
    CGFloat labelWidth = self.bounds.size.width;
    
    
    
    
    _mainView=[[UIView alloc]initWithFrame:CGRectMake(20, 20, self.bounds.size.width-40, self.bounds.size.height-40)];
    _mainView.backgroundColor=[UIColor clearColor];
    [self addSubview:_mainView];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:_mainView andWithBlick:^(UIView *view) {
        if (self.clickBlock) {
            self.clickBlock(_mainView);
        }
    }];
    
    
    
    _dayLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,4,labelWidth-15*2,21)];
    _dayLabel.font = [UIFont systemFontOfSize:14];
    _dayLabel.textAlignment = NSTextAlignmentLeft;
    _dayLabel.font = [UIFont fontWithName:@ "Arial Rounded MT Bold"  size:(13)];
    _dayLabel.textColor = [UIColor blackColor];
    _dayLabel.text=@"****-**-**";
    [self addSubview:_dayLabel];
    
    _timeLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(_dayLabel.frame)-4,labelWidth-15*2,21)];
    _timeLabel.font = [UIFont systemFontOfSize:14];
    _timeLabel.textAlignment = NSTextAlignmentLeft;
    _timeLabel.textColor = [UIColor colorWithHexString:@"#2e2e2e"];
    _timeLabel.text=@"--:--";
    [self addSubview:_timeLabel];
    
    _timeDiviLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(_timeLabel.frame),38,2)];
    _timeDiviLabel.backgroundColor=[UIColor colorWithHexString:@"#349ef7"];
    [self addSubview:_timeDiviLabel];
    
    _msgContentLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(_timeLabel.frame)+4,labelWidth-15*2,42)];
    _msgContentLabel.font = [UIFont systemFontOfSize:13];
    _msgContentLabel.textAlignment = NSTextAlignmentLeft;
    _msgContentLabel.numberOfLines=2;
    _msgContentLabel.textColor = [UIColor colorWithHexString:@"#2e2e2e"];
    _msgContentLabel.text=@"--";
    [self addSubview:_msgContentLabel];
    
}

-(void)setItem:(XLCardItem *)item {
    SINAMsgItemModel *msgItemModel = item.msgItemModel;
    _dayLabel.text= [SINACalendarUtils getDateStringWithTimeStr:msgItemModel.time andFormat:@"yyyy-MM-dd"];
    _timeLabel.text= [SINACalendarUtils getDateStringWithTimeStr:msgItemModel.time andFormat:@"HH:mm"];
    _msgContentLabel.text=msgItemModel.msgContent;
}

@end
